import Dialog from '../../../dist/dialog/dialog';
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current_index: 0,
    list: [],
    page: 1,
    total_page: 1,
    status_list: [
      {
        text: "全部",
        apply_status: 0
      },
      {
        text: "待审核",
        apply_status: 1
      },
      {
        text: "审核通过",
        apply_status: 2
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },
  choose(e) {
    let apply_status = e.currentTarget.dataset.status;
    this.setData({current_index:apply_status});
    this.getData({ apply_status, page: 1 });
  },
  apply_handle(e) {
    let id = e.currentTarget.dataset.id;
    let type = e.currentTarget.dataset.type;
    let message = '';
    if (type == 'pass') {
      message = "是否确认通过该门店申请？"
    } else {
      message = "是否确认驳回该门店申请？"
    }
    Dialog.confirm({
      message,
    }).then(() => {
      let urlStr = '';
      if (type == 'pass') {
        urlStr = 'plugin.store-cashier.frontend.store.parent-apply.accept';
      } else {
        urlStr = 'plugin.store-cashier.frontend.store.parent-apply.reject';
      }
      app._getNetWork({
        url:app.getNetAddresss(urlStr),
        data:{id},
        success:resdata=>{
          let {result,msg} = resdata.data;
          app.tips(msg);
          if(result == 1){
            this.getData({apply_status:this.data.current_index})
          }
        }
      })
    })
      .catch(() => {
        // on cancel
      });
  },
  store_applyfor_details(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageI/store_audit/details/details?id='+id,
    })
  },
  getMoreData() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    let json = {
      apply_status:this.data.current_index,
      page
    };
    this.getData(json)
  },
  getData(json) {
    app._postNetWork({
      url: app.getNetAddresss('plugin.store-cashier.frontend.store.parent-apply.index'),
      data: json,
      success: resdata => {
        let {
          result,
          msg,
          data:{current_page,last_page,data}
        } = resdata.data;
        if (result == 0) {
          return app.tips(msg)
        }
        this.setData({
          page: current_page,
          total_page: last_page
        })

        if (current_page == 1) {
          this.setData({
            list: data || []
          })
        } else {
          this.setData({
            list: this.data.list.concat(data)
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})